/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("subcontracting_plan",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.DomainModels;
using ATkg.BizAppProject.IServices;
using Microsoft.AspNetCore.Authorization;
using static ATkg.BizAppProject.Services.material_plan_xieService;
using DGZImp.Core.EFDbContext;
using DGZImp.Core.Extensions;
using Newtonsoft.Json.Linq;

namespace ATkg.BizAppProject.Controllers
{
    public partial class subcontracting_planController
    {
        private readonly Isubcontracting_planService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        public ISqlSugarClient Db = AutofacContainerModule.GetService<ServiceDbContext>()?.SqlSugarClient;

        [ActivatorUtilitiesConstructor]
        public subcontracting_planController(
            Isubcontracting_planService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        [HttpGet("get_weituo_plan")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_weituo_plan()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {

            Console.WriteLine("get方法调用");

            Console.WriteLine("get方法调用");
            var a = await Service.get_info_from_daojiao();
            var a1 = await Service.get_info_from_jianbao();



            var ak = await Service.get_info_from_daojiao_ak();
            var ak1 = await Service.get_info_from_jianbao_ak();


            var bf = await Service.get_info_from_daojiao_bf();
            var bf1 = await Service.get_info_from_jianbao_bf();
            var r = "1111";
            return new List<object>
            {
                a.GetLong(),
                a
            };
        }

        [HttpGet("get_data_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> get_data_db()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_db_data();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }

        [HttpGet("get_weituo_plan_ak")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_weituo_plan_ak()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {

            Console.WriteLine("get方法调用");

            Console.WriteLine("get方法调用");
            var a = await Service.get_info_from_daojiao_ak();
            var a1 = await Service.get_info_from_jianbao_ak();

            var r = "1111";
            return new List<object>
            {
                a.GetLong(),
                a
            };
        }


        [HttpGet("get_weituo_plan_bf")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_weituo_plan_bf()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {

            Console.WriteLine("get方法调用");

            Console.WriteLine("get方法调用");
            var a = await Service.get_info_from_daojiao_bf();
            var a1 = await Service.get_info_from_jianbao_bf();

            var r = "1111";
            return new List<object>
            {
                a1.GetLong(),
                a1
            };
        }


        [HttpGet("get_yuanfa_product")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_yuanfa_product()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {

            Console.WriteLine("get方法调用");
            var proname = "5115";

            var zaiku_all = 0;
            var zaixian_all = 0;

            var list_bj = JArray.FromObject(await Service.get_yf_from_mes(proname));
            for (int i = 0; i < list_bj.Count; i++)
            {
                var per_ = JArray.FromObject(list_bj[i]);
                for (int j = 0; j < per_.Count; j++)
                {
                    var per_pro = per_[j];
                    zaiku_all += per_pro["在库数量"].Value<int>();
                    zaixian_all += per_pro["在线数量"].Value<int>();
                }
            }

            var list_ak = JArray.FromObject(await Service.get_yf_from_mes_ak(proname));
            for (int i = 0; i < list_ak.Count; i++)
            {
                var per_ = JArray.FromObject(list_ak[i]);
                for (int j = 0; j < per_.Count; j++)
                {
                    var per_pro = per_[j];
                    zaiku_all += per_pro["在库数量"].Value<int>();
                    zaixian_all += per_pro["在线数量"].Value<int>();
                }
            }


            var list_bf = JArray.FromObject(await Service.get_yf_from_mes_bf(proname));
            for (int i = 0; i < list_bf.Count; i++)
            {
                var per_ = JArray.FromObject(list_bf[i]);
                for (int j = 0; j < per_.Count; j++)
                {
                    var per_pro = per_[j];
                    zaiku_all += per_pro["在库数量"].Value<int>();
                    zaixian_all += per_pro["在线数量"].Value<int>();
                }
            }

            Console.WriteLine("KKKKKKKKKKKKKKKKKK");
            Console.WriteLine(zaiku_all);
            Console.WriteLine(zaixian_all);
            Console.WriteLine("111111111111111111");
            var r = "1111";
            return new List<object>
            {
                list_bf.GetLong(),
                list_bf
            };
        }
    }
}
